﻿/**  版本信息模板在安装目录下，可自行修改。
* offer.cs
*
* 功 能： N/A
* 类 名： offer
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/1/2 22:18:53   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using ZGEDrySaltery.IDAL;
using Maticsoft.DBUtility;//Please add references
namespace ZGEDrySaltery.MySQLDAL
{
	/// <summary>
	/// 数据访问类:offer
	/// </summary>
	public partial class offer:Ioffer
	{
		public offer()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperMySQL.GetMaxID("OFFERID", "offer"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int OFFERID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from offer");
			strSql.Append(" where OFFERID=@OFFERID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@OFFERID", MySqlDbType.Int32)
			};
			parameters[0].Value = OFFERID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ZGEDrySaltery.Model.offer model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into offer(");
			strSql.Append("COMPANYID,USERID,USERNAME,REALNAME,TITLE,UNIT,SPECIFICATIONSSTR,VIPPRICE,MARKETPRICE,MINPRICE,PIFAPRICE,PCID,INTRO,AREA,RECOMMEND,SORT,IMAGES,INVENTORYCOUNT,TRADETOTAL,STATE,MEMO,INSERTTIME,MODIFYTIME,F1,F2,F3,F4)");
			strSql.Append(" values (");
			strSql.Append("@COMPANYID,@USERID,@USERNAME,@REALNAME,@TITLE,@UNIT,@SPECIFICATIONSSTR,@VIPPRICE,@MARKETPRICE,@MINPRICE,@PIFAPRICE,@PCID,@INTRO,@AREA,@RECOMMEND,@SORT,@IMAGES,@INVENTORYCOUNT,@TRADETOTAL,@STATE,@MEMO,@INSERTTIME,@MODIFYTIME,@F1,@F2,@F3,@F4)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@COMPANYID", MySqlDbType.Int32,11),
					new MySqlParameter("@USERID", MySqlDbType.Int32,11),
					new MySqlParameter("@USERNAME", MySqlDbType.VarChar,36),
					new MySqlParameter("@REALNAME", MySqlDbType.VarChar,36),
					new MySqlParameter("@TITLE", MySqlDbType.VarChar,512),
					new MySqlParameter("@UNIT", MySqlDbType.VarChar,32),
					new MySqlParameter("@SPECIFICATIONSSTR", MySqlDbType.VarChar,64),
					new MySqlParameter("@VIPPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@MARKETPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@MINPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@PIFAPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@PCID", MySqlDbType.Int32,11),
					new MySqlParameter("@INTRO", MySqlDbType.VarChar,1024),
					new MySqlParameter("@AREA", MySqlDbType.VarChar,64),
					new MySqlParameter("@RECOMMEND", MySqlDbType.Int32,11),
					new MySqlParameter("@SORT", MySqlDbType.Int32,11),
					new MySqlParameter("@IMAGES", MySqlDbType.VarChar,256),
					new MySqlParameter("@INVENTORYCOUNT", MySqlDbType.Int32,11),
					new MySqlParameter("@TRADETOTAL", MySqlDbType.Int32,11),
					new MySqlParameter("@STATE", MySqlDbType.Int32,11),
					new MySqlParameter("@MEMO", MySqlDbType.VarChar,256),
					new MySqlParameter("@INSERTTIME", MySqlDbType.DateTime),
					new MySqlParameter("@MODIFYTIME", MySqlDbType.DateTime),
					new MySqlParameter("@F1", MySqlDbType.VarChar,256),
					new MySqlParameter("@F2", MySqlDbType.VarChar,256),
					new MySqlParameter("@F3", MySqlDbType.VarChar,256),
					new MySqlParameter("@F4", MySqlDbType.VarChar,256)};
			parameters[0].Value = model.COMPANYID;
			parameters[1].Value = model.USERID;
			parameters[2].Value = model.USERNAME;
			parameters[3].Value = model.REALNAME;
			parameters[4].Value = model.TITLE;
			parameters[5].Value = model.UNIT;
			parameters[6].Value = model.SPECIFICATIONSSTR;
			parameters[7].Value = model.VIPPRICE;
			parameters[8].Value = model.MARKETPRICE;
			parameters[9].Value = model.MINPRICE;
			parameters[10].Value = model.PIFAPRICE;
			parameters[11].Value = model.PCID;
			parameters[12].Value = model.INTRO;
			parameters[13].Value = model.AREA;
			parameters[14].Value = model.RECOMMEND;
			parameters[15].Value = model.SORT;
			parameters[16].Value = model.IMAGES;
			parameters[17].Value = model.INVENTORYCOUNT;
			parameters[18].Value = model.TRADETOTAL;
			parameters[19].Value = model.STATE;
			parameters[20].Value = model.MEMO;
			parameters[21].Value = model.INSERTTIME;
			parameters[22].Value = model.MODIFYTIME;
			parameters[23].Value = model.F1;
			parameters[24].Value = model.F2;
			parameters[25].Value = model.F3;
			parameters[26].Value = model.F4;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ZGEDrySaltery.Model.offer model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update offer set ");
			strSql.Append("COMPANYID=@COMPANYID,");
			strSql.Append("USERID=@USERID,");
			strSql.Append("USERNAME=@USERNAME,");
			strSql.Append("REALNAME=@REALNAME,");
			strSql.Append("TITLE=@TITLE,");
			strSql.Append("UNIT=@UNIT,");
			strSql.Append("SPECIFICATIONSSTR=@SPECIFICATIONSSTR,");
			strSql.Append("VIPPRICE=@VIPPRICE,");
			strSql.Append("MARKETPRICE=@MARKETPRICE,");
			strSql.Append("MINPRICE=@MINPRICE,");
			strSql.Append("PIFAPRICE=@PIFAPRICE,");
			strSql.Append("PCID=@PCID,");
			strSql.Append("INTRO=@INTRO,");
			strSql.Append("AREA=@AREA,");
			strSql.Append("RECOMMEND=@RECOMMEND,");
			strSql.Append("SORT=@SORT,");
			strSql.Append("IMAGES=@IMAGES,");
			strSql.Append("INVENTORYCOUNT=@INVENTORYCOUNT,");
			strSql.Append("TRADETOTAL=@TRADETOTAL,");
			strSql.Append("STATE=@STATE,");
			strSql.Append("MEMO=@MEMO,");
			strSql.Append("INSERTTIME=@INSERTTIME,");
			strSql.Append("MODIFYTIME=@MODIFYTIME,");
			strSql.Append("F1=@F1,");
			strSql.Append("F2=@F2,");
			strSql.Append("F3=@F3,");
			strSql.Append("F4=@F4");
			strSql.Append(" where OFFERID=@OFFERID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@COMPANYID", MySqlDbType.Int32,11),
					new MySqlParameter("@USERID", MySqlDbType.Int32,11),
					new MySqlParameter("@USERNAME", MySqlDbType.VarChar,36),
					new MySqlParameter("@REALNAME", MySqlDbType.VarChar,36),
					new MySqlParameter("@TITLE", MySqlDbType.VarChar,512),
					new MySqlParameter("@UNIT", MySqlDbType.VarChar,32),
					new MySqlParameter("@SPECIFICATIONSSTR", MySqlDbType.VarChar,64),
					new MySqlParameter("@VIPPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@MARKETPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@MINPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@PIFAPRICE", MySqlDbType.Decimal,10),
					new MySqlParameter("@PCID", MySqlDbType.Int32,11),
					new MySqlParameter("@INTRO", MySqlDbType.VarChar,1024),
					new MySqlParameter("@AREA", MySqlDbType.VarChar,64),
					new MySqlParameter("@RECOMMEND", MySqlDbType.Int32,11),
					new MySqlParameter("@SORT", MySqlDbType.Int32,11),
					new MySqlParameter("@IMAGES", MySqlDbType.VarChar,256),
					new MySqlParameter("@INVENTORYCOUNT", MySqlDbType.Int32,11),
					new MySqlParameter("@TRADETOTAL", MySqlDbType.Int32,11),
					new MySqlParameter("@STATE", MySqlDbType.Int32,11),
					new MySqlParameter("@MEMO", MySqlDbType.VarChar,256),
					new MySqlParameter("@INSERTTIME", MySqlDbType.DateTime),
					new MySqlParameter("@MODIFYTIME", MySqlDbType.DateTime),
					new MySqlParameter("@F1", MySqlDbType.VarChar,256),
					new MySqlParameter("@F2", MySqlDbType.VarChar,256),
					new MySqlParameter("@F3", MySqlDbType.VarChar,256),
					new MySqlParameter("@F4", MySqlDbType.VarChar,256),
					new MySqlParameter("@OFFERID", MySqlDbType.Int32,11)};
			parameters[0].Value = model.COMPANYID;
			parameters[1].Value = model.USERID;
			parameters[2].Value = model.USERNAME;
			parameters[3].Value = model.REALNAME;
			parameters[4].Value = model.TITLE;
			parameters[5].Value = model.UNIT;
			parameters[6].Value = model.SPECIFICATIONSSTR;
			parameters[7].Value = model.VIPPRICE;
			parameters[8].Value = model.MARKETPRICE;
			parameters[9].Value = model.MINPRICE;
			parameters[10].Value = model.PIFAPRICE;
			parameters[11].Value = model.PCID;
			parameters[12].Value = model.INTRO;
			parameters[13].Value = model.AREA;
			parameters[14].Value = model.RECOMMEND;
			parameters[15].Value = model.SORT;
			parameters[16].Value = model.IMAGES;
			parameters[17].Value = model.INVENTORYCOUNT;
			parameters[18].Value = model.TRADETOTAL;
			parameters[19].Value = model.STATE;
			parameters[20].Value = model.MEMO;
			parameters[21].Value = model.INSERTTIME;
			parameters[22].Value = model.MODIFYTIME;
			parameters[23].Value = model.F1;
			parameters[24].Value = model.F2;
			parameters[25].Value = model.F3;
			parameters[26].Value = model.F4;
			parameters[27].Value = model.OFFERID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int OFFERID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from offer ");
			strSql.Append(" where OFFERID=@OFFERID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@OFFERID", MySqlDbType.Int32)
			};
			parameters[0].Value = OFFERID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string OFFERIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from offer ");
			strSql.Append(" where OFFERID in ("+OFFERIDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZGEDrySaltery.Model.offer GetModel(int OFFERID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select OFFERID,COMPANYID,USERID,USERNAME,REALNAME,TITLE,UNIT,SPECIFICATIONSSTR,VIPPRICE,MARKETPRICE,MINPRICE,PIFAPRICE,PCID,INTRO,AREA,RECOMMEND,SORT,IMAGES,INVENTORYCOUNT,TRADETOTAL,STATE,MEMO,INSERTTIME,MODIFYTIME,F1,F2,F3,F4 from offer ");
			strSql.Append(" where OFFERID=@OFFERID");
			MySqlParameter[] parameters = {
					new MySqlParameter("@OFFERID", MySqlDbType.Int32)
			};
			parameters[0].Value = OFFERID;

			ZGEDrySaltery.Model.offer model=new ZGEDrySaltery.Model.offer();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ZGEDrySaltery.Model.offer DataRowToModel(DataRow row)
		{
			ZGEDrySaltery.Model.offer model=new ZGEDrySaltery.Model.offer();
			if (row != null)
			{
				if(row["OFFERID"]!=null && row["OFFERID"].ToString()!="")
				{
					model.OFFERID=int.Parse(row["OFFERID"].ToString());
				}
				if(row["COMPANYID"]!=null && row["COMPANYID"].ToString()!="")
				{
					model.COMPANYID=int.Parse(row["COMPANYID"].ToString());
				}
				if(row["USERID"]!=null && row["USERID"].ToString()!="")
				{
					model.USERID=int.Parse(row["USERID"].ToString());
				}
				if(row["USERNAME"]!=null)
				{
					model.USERNAME=row["USERNAME"].ToString();
				}
				if(row["REALNAME"]!=null)
				{
					model.REALNAME=row["REALNAME"].ToString();
				}
				if(row["TITLE"]!=null)
				{
					model.TITLE=row["TITLE"].ToString();
				}
				if(row["UNIT"]!=null)
				{
					model.UNIT=row["UNIT"].ToString();
				}
				if(row["SPECIFICATIONSSTR"]!=null)
				{
					model.SPECIFICATIONSSTR=row["SPECIFICATIONSSTR"].ToString();
				}
				if(row["VIPPRICE"]!=null && row["VIPPRICE"].ToString()!="")
				{
					model.VIPPRICE=decimal.Parse(row["VIPPRICE"].ToString());
				}
				if(row["MARKETPRICE"]!=null && row["MARKETPRICE"].ToString()!="")
				{
					model.MARKETPRICE=decimal.Parse(row["MARKETPRICE"].ToString());
				}
				if(row["MINPRICE"]!=null && row["MINPRICE"].ToString()!="")
				{
					model.MINPRICE=decimal.Parse(row["MINPRICE"].ToString());
				}
				if(row["PIFAPRICE"]!=null && row["PIFAPRICE"].ToString()!="")
				{
					model.PIFAPRICE=decimal.Parse(row["PIFAPRICE"].ToString());
				}
				if(row["PCID"]!=null && row["PCID"].ToString()!="")
				{
					model.PCID=int.Parse(row["PCID"].ToString());
				}
				if(row["INTRO"]!=null)
				{
					model.INTRO=row["INTRO"].ToString();
				}
				if(row["AREA"]!=null)
				{
					model.AREA=row["AREA"].ToString();
				}
				if(row["RECOMMEND"]!=null && row["RECOMMEND"].ToString()!="")
				{
					model.RECOMMEND=int.Parse(row["RECOMMEND"].ToString());
				}
				if(row["SORT"]!=null && row["SORT"].ToString()!="")
				{
					model.SORT=int.Parse(row["SORT"].ToString());
				}
				if(row["IMAGES"]!=null)
				{
					model.IMAGES=row["IMAGES"].ToString();
				}
				if(row["INVENTORYCOUNT"]!=null && row["INVENTORYCOUNT"].ToString()!="")
				{
					model.INVENTORYCOUNT=int.Parse(row["INVENTORYCOUNT"].ToString());
				}
				if(row["TRADETOTAL"]!=null && row["TRADETOTAL"].ToString()!="")
				{
					model.TRADETOTAL=int.Parse(row["TRADETOTAL"].ToString());
				}
				if(row["STATE"]!=null && row["STATE"].ToString()!="")
				{
					model.STATE=int.Parse(row["STATE"].ToString());
				}
				if(row["MEMO"]!=null)
				{
					model.MEMO=row["MEMO"].ToString();
				}
				if(row["INSERTTIME"]!=null && row["INSERTTIME"].ToString()!="")
				{
					model.INSERTTIME=DateTime.Parse(row["INSERTTIME"].ToString());
				}
				if(row["MODIFYTIME"]!=null && row["MODIFYTIME"].ToString()!="")
				{
					model.MODIFYTIME=DateTime.Parse(row["MODIFYTIME"].ToString());
				}
				if(row["F1"]!=null)
				{
					model.F1=row["F1"].ToString();
				}
				if(row["F2"]!=null)
				{
					model.F2=row["F2"].ToString();
				}
				if(row["F3"]!=null)
				{
					model.F3=row["F3"].ToString();
				}
				if(row["F4"]!=null)
				{
					model.F4=row["F4"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select OFFERID,COMPANYID,USERID,USERNAME,REALNAME,TITLE,UNIT,SPECIFICATIONSSTR,VIPPRICE,MARKETPRICE,MINPRICE,PIFAPRICE,PCID,INTRO,AREA,RECOMMEND,SORT,IMAGES,INVENTORYCOUNT,TRADETOTAL,STATE,MEMO,INSERTTIME,MODIFYTIME,F1,F2,F3,F4 ");
			strSql.Append(" FROM offer ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM offer ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.OFFERID desc");
			}
			strSql.Append(")AS Row, T.*  from offer T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "offer";
			parameters[1].Value = "OFFERID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

